package com.zslibrary.Protocol;

import android.util.Log;

import com.zslibrary.BusMaster.HandleError;
import com.zslibrary.Enum.StateDefine;
import com.zslibrary.Structure.ErrorStruct;
import com.zslibrary.Structure.MessageStruct;
import com.zslibrary.Tools.FrameBuilder;
import com.zslibrary.Tools.HexBytesUtil;
import com.zslibrary.Tools.ZSLog;

public class CommonMessage {
    static public void processSetError(MessageStruct message){
        FrameBuilder msgBuilder=new FrameBuilder(message.messageData);
        byte[] err_bytes;
        err_bytes=msgBuilder.popBytes(message.messageLength-4);
        short component=(short)msgBuilder.popData(2);   /*暂时未使用*/
        Boolean isFatal=((msgBuilder.popData(1)==1)?true:false);
        Boolean isPersistent=((msgBuilder.popData(1))==1?true:false);
        ErrorStruct error=new ErrorStruct(new String(err_bytes),isFatal,isPersistent);
        HandleError.setError(error);
        //ZSLog.d("report error:"+error.errorCode);
    }

    static public void processClrError(MessageStruct message){
        FrameBuilder msgBuilder=new FrameBuilder(message.messageData);
        byte[] err_bytes;
        err_bytes=msgBuilder.popBytes(message.messageLength-2);
        HandleError.clearError(new String(err_bytes));
    }

//    static public void processReset(){
//        StateMachine.postStateEvent(StateEventDefine.EVT_RESET);
//    }

    static public @StateDefine.State int processBoardStatus(MessageStruct message){
        return HexBytesUtil.Bytes2Int(message.messageData);
    }

}
